﻿Public Class RecentAirdateConverter
    Implements IValueConverter

    Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
        Dim datetime = CDate(value)

        If datetime < New DateTime(2008, 12, 12) Then
            Return ""
        Else
            Dim text As String = ""
            Dim days = Now.Subtract(datetime).TotalDays
            Dim hours = Now.Subtract(datetime).TotalHours
            Dim minutes = Now.Subtract(datetime).TotalMinutes
            If days > 31 Then
                text = "1ヶ月以上前"
            ElseIf days >= 1 Then
                text = CInt(days).ToString & "日前"
            ElseIf hours >= 1 Then
                text = CInt(hours).ToString & "時間前"
            Else
                text = CInt(minutes).ToString & "分前"
            End If
            If text <> "" Then text = " (" & text & ")"
            Return datetime.ToString("MM月dd日 HH:mm") & text
        End If

    End Function

    Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
        Throw New NotSupportedException
    End Function
End Class
